﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _2QWebProxy.App_Code;

namespace _2QWebProxy.GUI
{
    public partial class ucPortList : UserControl
    {
        public ucPortList()
        {
            InitializeComponent();
            LoadPortList();
        }

        private void LoadPortList()
        {
            listBoxPort.Items.Clear();
            List<Port> ports = Utils.GetPortList();
            foreach (Port oPort in ports)
            {
                listBoxPort.Items.Add(oPort.PortNumber);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {

        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            int port;
            if (!Int32.TryParse(listBoxPort.SelectedItem.ToString(), out port))
            {
                MessageBox.Show("Invalid port number");
                return;
            }
            Utils.DeletePort(port);
            LoadPortList();
        }

        private void btnRemoveAll_Click(object sender, EventArgs e)
        {
            Utils.DeleteAllPort();
            LoadPortList();
        }
    }
}
